package com.example.changtest.util

import android.os.Environment
import android.util.Log
import org.web3j.crypto.ECKeyPair
import org.web3j.crypto.Keys
import org.web3j.crypto.WalletUtils
import org.web3j.utils.Numeric
import java.io.File
import java.security.KeyStore

/**
 * @Description:
 * @author: zcs
 * @email: 1059737741@qq.com
 * create at 2022/3/9 18:34
 */
object WalletTools {

    fun createWallet(pwd:String){
        val dir = Environment.getExternalStorageDirectory().path + "/wallet"
        var file = File(dir)
        if(!file.exists()){
            file.mkdirs()
        }
        val ecKeyPair = Keys.createEcKeyPair()
        //keystore文件名
        val filename = WalletUtils.generateWalletFile(pwd, ecKeyPair, file, false)
        //获取keystore内容
       val KeyStore = File(dir+"/"+ filename)
        Log.e("+++","keystore:"+KeyStore.getAbsolutePath())

        val msg = "fileName:" + filename + "\nprivateKey:" + Numeric.encodeQuantity(ecKeyPair.getPrivateKey())+ "\nPublicKey:" + Numeric.encodeQuantity(ecKeyPair.getPublicKey());
        Log.e("+++", "create:" + msg)

    }
}